(function (angular) {
    'use strict';

    angular.module('ytong.controllers').controller('managerCtrl',managerCtrl);

    function managerCtrl(authenticationService, $state, Constants, feedbacksManager, ModalService, $scope){

        $scope.$on('promisesChangedEvent', function (event, data) {
            if(data.isLoading){
                $('#managerLoading').modal('show');
            }else{
                $('#managerLoading').modal('hide');
            };
        });


        this.STATES = Constants.STATES;

        this.isActive = function(nav){
            return (nav === $state.current.name);
        };

        this.logout = function(){
            authenticationService.logout();
        };

        this.getMessagesCount = function(){
            return feedbacksManager.getUnreadMeesagesCount();
        };

        this.writeFeedback = function(){
            ModalService.showModal({
                templateUrl: 'editFeedback',
                controller: 'writeFeedbackCtrl as wfc'
            })
                .then(function(modal){
                    modal.element.modal();
                    modal.close.then(function(result){

                        if(result.action === Constants.COMMANDS.ADD){
                            feedbacksManager.addFeedback(result.feedback);
                        }
                    });
                });
        };
    };

}(angular));